import java.util.Arrays;

public class mst_01_02 {
    //面试题 01.02. 判定是否互为字符重排 简单
    public static void main(String[] args) {
        String s1 = "abcde";
        String s2 = "bdcea";
        System.out.println(CheckPermutation(s1, s2));
    }
    public static boolean CheckPermutation(String s1, String s2) {
        if(s1.length()!=s2.length()){
            return false;
        }else{
            if(mysort(s1).equals(mysort(s2))){
                return true;
            } else{
                return false;
            }
        }
    }
    public static String mysort(String str){
        char arr[] = str.toCharArray();
        Arrays.sort(arr);
        return new String(arr);
    }
    /************方法二：哈希表***************/
    public static boolean CheckPermutation2(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        } else {
            int arr[] = new int[128];
            for (int i = 0; i < s1.length(); i++) {
                arr[(char) s1.charAt(i)]++;
            }
            for (int i = 0; i < s2.length(); i++) {
                arr[(char) s2.charAt(i)]--;
                if (arr[(char) s2.charAt(i)]-- < 0) {
                    return false;
                }
            }
        }
        return true;
    }

}
